# -*- coding: utf-8 -*-

from django.db import models
from core.models import CoreModel, table_prefix


class Menu(CoreModel):
    parent = models.ForeignKey(
        null=True,
        blank=True,
        to="Menu",
        on_delete=models.CASCADE,
        db_constraint=False,
        verbose_name="上级菜单",
    )
    icon = models.CharField(max_length=64, default="#", verbose_name="菜单图标")
    name = models.CharField(max_length=64, verbose_name="菜单名称")
    type = models.CharField(default="M", max_length=64, verbose_name="菜单类型")
    link = models.CharField(
        null=True, blank=True, max_length=64, verbose_name="是否外链"
    )
    path = models.CharField(
        null=True, blank=True, max_length=128, verbose_name="路由地址"
    )
    component = models.CharField(
        null=True, blank=True, max_length=128, verbose_name="组件地址"
    )
    cache = models.CharField(max_length=32, default="0", verbose_name="缓存状态")
    visible = models.CharField(max_length=32, default="0", verbose_name="显示状态")
    query = models.CharField(null=True, blank=True, max_length=64, verbose_name="查询")
    perms = models.CharField(
        null=True, blank=True, max_length=128, verbose_name="权限标识"
    )
    nesting = models.BooleanField(null=True, blank=True, verbose_name="是否嵌套")
    redirect = models.CharField(
        null=True, blank=True, max_length=128, verbose_name="是否重定向"
    )

    class Meta:
        db_table = table_prefix + "system_menu"
        verbose_name = "菜单管理"
        verbose_name_plural = verbose_name
        ordering = ("sort",)
